1. Field of the Invention
The present invention relates generally to data processing, and particularly to reusing code in software development.
2. Technical Background
The JAVA programming language (herein sometimes called “JPL”) is an object-oriented programming language that was specifically designed by Sun Microsystems for use in a distributed computing environment. (The term JAVA may be subject to trademark rights.) Accordingly, JPL based applications may run on a single computer or be distributed among server computers and client computers in a network. As long as the computer has a JPL virtual machine, the program can run on that computer. JPL is also used to write small applications commonly referred to as “applets.” Applets are often provided to a client computer along with a web page. The JPL applet may perform the various functions that allow a user to interact with the web page somewhat independently from the server computer.
Computer programs have traditionally been action oriented and were written to implement a method or procedure. The method processed the input data to generate output data. Object-Oriented programming, on the other hand, models data to identify the objects that are to be manipulated and determine how the objects interrelate. Accordingly, there is a data hierarchy consisting of types, classes, and objects. Generally speaking there are two data types, primitive data and classes. Primitive data includes simple entities such as numbers and characters. Data classes are typically more complex and are user-defined to represent things other than numbers and characters. In Object-Oriented programming terminology, an object is referred to as an instance of a class. In other words, if “customer” represents the class, then a particular customer, “John Smith,” would be an object within the customer class.
Each class is defined as having attributes. For example, the customer class may include attributes such as last name, first name, address, email address, telephone number, financial data, and etc. While every object in the class may include all of these attributes, each object will typically have different values associated with the attributes. A class may have one or more “behaviors” associated with it. A behavior is a method that may be performed by the objects within the class. An object may call its own methods, or may call another object's methods, if that object is visible. An 'object is created within the class by a method known as a constructor. The JPL virtual machine will assign the newly created object a reference identifier that uniquely identifies the object within the virtual machine. An object may communicate with another object by transmitting a message. In the message, the first object may provide data and invoke a method resident in the target object. The target object will execute the method using the data provided, and return a value to the original object. Many of the most useful object interactions have been catalogued. These object interactions are commonly referred to as “design patterns.”
A design pattern may be thought of as a solution to a recurring design problem. The recurring design problem will manifest itself in specific situations. As such, the design pattern that represents the solution conveniently allows programmer to re-use code that was previously developed and written. There are various types of design patterns. Creational design patterns create objects within a program. Structural design patterns organize discrete objects or groups of objects into a larger structure. Behavioral design patterns may define the communication between objects to control the flow in a complex computer program.
Accordingly, design Patterns are becoming increasingly popular in Object Oriented Design for solving commonly occurring design problems. Design patterns are easily used and identified in a newly developed system. However, it is not always obvious and easy to identify the design patterns that may have been used in an existing application. This difficulty arises in maintenance projects where the maintenance team did not build the application. Often, the design patterns used in the existing application were not documented by the team that built the application. As such, the maintenance team has no easy way of knowing what patterns were used to build the application. Of course, this is very important since awareness of the design patterns used in an application may help a maintenance team to better understand the implementation of the application. The team can also ensure that all future changes made to the application are in conformance to the design patterns used.
What is needed is a search technique for identifying portions of software code that have a predefined structure. This search technique should be implemented in an automated tool. One application for the automated tool is one that identifies design patterns in a source files. An automated tool that identifies design patterns in a set of JPL Source files would be particularly useful during application maintenance. An automated search tool is needed that includes a generic search engine that may be configured non-programmatically to find design patterns in JPL source code. Further, a mechanism is needed that would progressively add newer rules into the search engine to enhance the engine's ability to identify newer patterns or alternate implementations of existing patterns.
The present invention addresses the needs described above. The present invention implements a technique that identifies design patterns in source code. In one embodiment, the present invention includes an automated tool that searches for design patterns in JPL Source Files. In particular, a generic search engine may be configured non-programmatically to look through JPL source code for implementations of patterns. The present invention may be configured to specify newer implementations of patterns for the generic search engine. The present invention also provides a mechanism that progressively adds newer rules into the search engine to enhance its ability to identify newer patterns or alternate implementations of existing patterns. The present invention breaks-up the design patterns into “atomic search units.” The search units may then be arranged in many different ways to specify the patterns to the search engine.
One aspect of the present invention is directed to a computerized method for identifying at least one pattern in source code. The method includes the step of parsing the source code to obtain data corresponding to at least one source code class. A plurality of search units are provided, each search unit being configured to evaluate a single verifiable property of the at least one source code class to a TRUE state or a FALSE state. At least a portion of the plurality of search units are arranged in at least one predetermined search sequence. The at least one source code class is evaluated by each search unit included in the at least one predetermined sequence to determine if the at least one pattern is identified.
In another aspect, the present invention is directed to a computerized system for identifying at least one pattern in source code. The system includes means for parsing the source code to obtain data corresponding to at least one source code class. Means for providing a plurality of search units is also provided. Each search unit is configured to evaluate a single verifiable property of a class to a TRUE state or a FALSE state. The system includes means for arranging at least a portion of the plurality of search units in at least one predetermined search sequence. Means are provided for evaluating each search unit in the at least one predetermined sequence to determine if the at least one pattern is identified.
In another aspect, the present invention is directed to a computerized system for identifying at least one pattern in source code. The system includes at least one data storage component configured to store data corresponding to at least one source code class and at least one file. The at least one file includes a plurality of search units arranged in at least one predetermined search sequence. Each search unit is configured to evaluate a single verifiable property of the at least one source code class to a TRUE state or a FALSE state. A computer system is coupled to the at least one data storage component. A search engine is configured to run on the computer system. The search engine is configured load the at least one file such that the plurality of search units evaluate the data corresponding to at least one source code class in the at least one predetermined search sequence to determine if the at least one pattern is identified.
Additional features and advantages of the invention will be set forth in the detailed description which follows, and in part will be readily apparent to those skilled in the art from that description or recognized by practicing the invention as described herein, including the detailed description which follows, the claims, as well as the appended drawings.
It is to be understood that both the foregoing general description and the following detailed description are merely exemplary of the invention, and are intended to provide an overview or framework for understanding the nature and character of the invention as it is claimed. The accompanying drawings are included to provide a further understanding of the invention, and are incorporated in and constitute a part of this specification. The drawings illustrate various embodiments of the invention, and together with the description serve to explain the principles and operation of the invention.